import axios from 'axios'
// ajax 请求封装

const instance = axios.create({
  baseURL: 'http://127.0.0.1:8000/',
  timeout: 1000,
  headers: {
    'X-Custom-Header': 'foobar',
    'Content-Type': 'application/json'
  }
})
instance.defaults.headers.post.Authorization = 'Beareraaeeewww'
export function axiosPost (url, data) {
  return new Promise((resolve, reject) => {
    instance.post(url, data).then(res => {
      if (res.data.code === 401) {
        localStorage.clear()
        sessionStorage.clear()
        reject(res.data)
      } else {
        resolve(res.data)
      }
    })
  }
  )
}

export const Login = data => axiosPost('/login', data)
